﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DAL.ArtworkLike;

namespace BLL.ArtworkLike
{
    public class ArtworkLikeService : IArtworkLikeService
    {
        private ArtworkLikeDao likeDao = new ArtworkLikeDao();

        /// <summary>
        /// 判断用户是否点赞作品
        /// </summary>
        /// <param name="artworkLikeId">作品id</param>
        /// <param name="ownerId">用户id</param>
        /// <returns>true为已经点赞，反之则未点赞</returns>
        public bool ExistLikeArtwork(int artworkId, int ownerId)
        {
            Models.ArtworkLikes artworkLike = GetArtworkLike(artworkId, ownerId);
            return artworkLike != null;
        }

        /// <summary>
        /// 获取点赞信息
        /// </summary>
        /// <param name="artworkId">作品id</param>
        /// <param name="ownerId">用户id</param>
        /// <returns>点赞实体类</returns>
        public ArtworkLikes GetArtworkLike(int artworkId, int ownerId)
        {
            return likeDao.GetArtworkLikeById(artworkId, ownerId);
        }

        /// <summary>
        /// 点赞作品
        /// </summary>
        /// <param name="artworkLike">作品实体类</param>
        /// <returns>true点赞成功，反之则失败</returns>
        public bool LikeArtwork(ArtworkLikes artworkLike)
        {
            likeDao.InsertArtworkLike(artworkLike);
            return artworkLike.LikeID != null;
        }

        /// <summary>
        /// 取消点赞作品
        /// </summary>
        /// <param name="artworkLike">作品实体类</param>
        /// <returns>true则取消点赞成功，反之则失败</returns>
        public bool UnLikeArtwork(ArtworkLikes artworkLike)
        {
            return likeDao.DeleteArtworkLike(artworkLike);
        }
    }
}
